import os


def replace_gt_with_rgb(path):
    # 遍历指定路径下的所有文件和子文件夹
    for root, dirs, files in os.walk(path):
        for file_name in files:
            # 替换文件名中的 'x' 为 'y'
            new_file_name = file_name.replace('_m', '')

            # 构建旧文件的完整路径
            old_file_path = os.path.join(root, file_name)
            # 构建新文件的完整路径
            new_file_path = os.path.join(root, new_file_name)

            # 重命名文件
            os.rename(old_file_path, new_file_path)
            print(f"Renamed '{file_name}' to '{new_file_name}'")



path_to_files = '/media/jolly/HIK/Brain Tumor Segmentation Dataset/val/label1/'
replace_gt_with_rgb(path_to_files)